# @Version        : 1.0
# @Update Time    : 2025/8/19 8:26
# @File           : __init__.py.py
# @IDE            : PyCharm
# @Desc           : 文件描述信息

from fastapi import FastAPI
from starlette.middleware.sessions import SessionMiddleware

from applications import settings
from applications.common.user_manager import manager
from applications.core.middlewares.demo_env_middleware import DemoEnvMiddleware
from applications.core.middlewares.link_track_middleware import LinkTrackMiddleware
from applications.core.middlewares.log_middleware import LogMiddleware
from applications.core.middlewares.operation_record_middleware import OperationRecordMiddleware


# 中间件注册
def register_middleware(app: FastAPI) -> None:
    app.add_middleware(LogMiddleware)  # type: ignore
    app.add_middleware(OperationRecordMiddleware)  # type: ignore
    manager.attach_middleware(app)
    app.add_middleware(
        SessionMiddleware,  # type: ignore
        secret_key=settings.SECRET_KEY,
    )
    app.add_middleware(DemoEnvMiddleware)  # type: ignore
    app.add_middleware(LinkTrackMiddleware)  # type: ignore
